<template>
	<view class="">
		<view class="topaddress">
			<view class="topaddressa">
				<view class="lxr">
					<view class="">
						联系人
					</view>
					<view class="">
						<input v-model="name" type="text" placeholder="如:张三" />
					</view>
				</view>
				
				<view class="lxdianhua">
					<view class="">
						联系电话
					</view>
					<view class="" style="margin-left: 200rpx;">
						<input v-model="phone" type="text" placeholder="如:13333333333" />
					</view>
					<view class="">
						<u-icon name="phone" color="#ccc" size="28"></u-icon>
					</view>
					
					
				</view>
				<view class="otherAddress" @click="getDizhi">
					<view class="">
						选择地址
					</view>
					<view class="" style="margin-left: 180rpx;">
						{{xuanze}}
					</view>
					<view class="">
						<u-icon name="arrow-right" color="#ccc" size="28"></u-icon>
					</view>
				</view>
				
				<view class="addressDetail">
					<view class="">
						详细地址
					</view>
					<input v-model="addDetail" type="text" placeholder="详细地址(如门牌号)" />
					
					
				</view>
				
				<view class="biaoqian">
					<view class="">
						标签
					</view>
					<view class="">
						<input v-model="tabs" type="text" placeholder="如:家里,公司,非必填" />
					</view>
					
				</view>
				
			</view>
			
			
		</view>
		
		<view v-if="type == 0" class="queding" @click="newAddress">
			确定
		</view>
		
		<view v-if="type == 1" class="queding" @click="sortAddress">
			修改
		</view>
		
		
	</view>
	
</template>

<script>
	export default{
		data(){
			return {
				address:'',
				xuanze:'',
				name:'',
				phone:'',
				addDetail:'',
				tabs:'',
				
				id:'',
				type:'',
				
			}
		},
		onShow() {
			this.xuanze = uni.getStorageSync('otherAddress')
		},
		onLoad(option) {
			console.log(option,'查看option是什么')
			this.name = option.name
			this.phone = option.phone
			this.xuanze = option.detail
			this.id = option.id
			this.type = option.type
			
		},
		methods:{
			getDizhi(){
				  wx.chooseLocation({
					  success: function(res) {
						console.log('succes1')
						console.log(res)
						this.address = res.name
						console.log(this.address,'addressaddress')
						uni.setStorageSync('otherAddress',this.address)
					  },
					  fail: function(fail) {
						  console.log(fail,'failfailfail')
						wx.getSetting({
						  success(res) {
							if (!res.authSetting['scope.userLocation']) {
							  console.log("f1")
							  wx.authorize({
								scope: 'scope.userLocation',
								success() {
								  wx.chooseLocation({
									success: function(res) {
									  that.setData({
										addr: res.address //调用成功直接设置地址
									  })
									},
								  })
								  console.log('success2')
								},
								fail(){
								  console.log("f2")
								}
							  })
							}
						  }
						})
					  }
					})

				
			},
			newAddress(){
				this.$req('POST',this.$api.addAddress,{
					name:this.name,
					phone:this.phone,
					detail:this.xuanze,
					user_id:uni.getStorageSync('userId'),
					school_id:uni.getStorageSync('addressId'),
					floor:this.addDetail,
					is_default:0,
					d_address:this.tabs
					
				}).then(res =>{
					if(res.status == 200){
						uni.navigateBack()
					}
					
				})
				
				
				
			}, 
			sortAddress(){  
				this.$req('POST',this.$api.adressXiu,{
					name:this.name,
					phone:this.phone,
					detail:this.xuanze,
					user_id:uni.getStorageSync('userId'),
					school_id:uni.getStorageSync('addressId'),
					floor:this.addDetail,
					is_default:1,
					id:this.id
					
				}).then(res =>{
					if(res.status == 200){
						uni.navigateBack()
					}
					
				})
			}
			
			
			
			
		}
		
	}
</script>

<style>
	page {
		background: #eee;
	}
	
	.topaddress{
		width: 95%;
		border-radius: 20rpx;
		background-color: #fff;
		margin: 30rpx auto;
	}
	
	.topaddressa{
		width: 95%;
		border-radius: 20rpx;
		background-color: #fff;
		margin: 30rpx auto;
	}
	
	.lxr{
		width: 100%;
		height: 80rpx;
		align-items: center;
		padding: 10rpx;
		display: flex;
		border-bottom: 2rpx solid #ccc;
		justify-content: space-between;
	}
	
	.lxdianhua{
		width: 100%;
		height: 80rpx;
		align-items: center;
		padding: 10rpx;
		display: flex;
		border-bottom: 2rpx solid #ccc;
		justify-content: space-between;
	}
	
	.otherAddress{
		width: 100%;
		height: 80rpx;
		align-items: center;
		padding: 10rpx;
		display: flex;
		border-bottom: 2rpx solid #ccc;
		justify-content: space-between;
	}
	
	.addressDetail{
		width: 100%;
		height: 80rpx;
		align-items: center;
		padding: 10rpx;
		display: flex;
		border-bottom: 2rpx solid #ccc;
		justify-content: space-between;
	}
	
	.biaoqian{
		width: 100%;
		height: 80rpx;
		align-items: center;
		padding: 10rpx;
		display: flex;
		justify-content: space-between;
	}
	
	.queding{
		width: 95%;
		height: 80rpx;
		border-radius: 30rpx;
		background-color: rgba(238,66,53);
		color: #fff;
		text-align: center;
		line-height: 80rpx;
		margin: 0 auto;
		
	}
	
	
	
	
</style>